package io.bluerain.intent;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

/**
 * Created by foredawn on 15-9-13.
 * Intent的两种用途
 */
public class IntentActivity extends Activity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.intent_activity);
    }

    public void startActivity(View source) {
        Intent intent = new Intent();
        ComponentName comp = new ComponentName(IntentActivity.this, SecondActivity.class);
        intent.setComponent(comp);
        startActivity(intent);
    }

    public void actionActivity(View source) {
        Intent intent = new Intent();
        intent.setAction(SecondActivity.ACTION); //包含此Action字符串的Activity都可能被启动
        startActivity(intent);
    }

    //返回桌面
    public void homeActivity(View source) {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        startActivity(intent);
    }

    public void call114(View source) {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_DIAL);
        String data = "tel:114";
        intent.setData(Uri.parse(data));
        startActivity(intent);
    }
}
